package Controler;

import java.util.ArrayList;

import Client.BusinessImplements;
/**
 * @author Lucie
 *class Add_new_Subject_controler
 *Class variables:msg,flag
 *Class methods:get_data,check_input,String get_msg,set_msg
 */
public class Add_new_Subject_controler {
	
	private String msg; 
	private boolean flag;
	
	/**
	 *  Constructor initializes the class variables
	 */
	public Add_new_Subject_controler ()
	{
		flag=true;
		msg=new String();
		msg=null;
	}
	/**
	 * 
	* @return String white all of the problems that occurred in the class
	 */
	public String get_msg()
	{
		return msg;
	}
	/**
	* @param new_msg
	 * This method chain messages into a string ,
	 *  the purpose ultimately is to display on the screen all the failures
	 */
	public void set_msg(String new_msg)
	{
		if (msg==null)
			msg=new_msg;
		else
		msg+=new_msg;
		
	}
	/**
	 * this  method call the class ;serverproxy, to Contact with the server,
	 * first we check if subject exist in the data base if this method return true 
	 * we can't add new subject otherwise we continue and add the subject to the data base
	 * @param sub_name
	 * @return  boolean:If the calls in the method failed it returns false otherwise returns true
	 */
	public boolean get_data(String sub_name)
	{
		 ArrayList<String> str_check= new  ArrayList<String>();
		 ArrayList<String> str_sub=new  ArrayList<String>();
		
		 
		 check_input( sub_name);
		 if (flag==false)
			 return false;
		 
		 str_check=BusinessImplements.GetInstance().getServerProxy().check_sub_exist(sub_name);
		 
		 if (str_check.get(0).equals("true"))
		 {
			 set_msg("\nSubject allready exist in the system"); 
			 return false;
		 }
		 
		 
		 str_sub=BusinessImplements.GetInstance().getServerProxy().add_subject(sub_name);
		 if (str_sub.get(0).equals("true"))
		 {
			 set_msg("\nsomthing went wrong please try again"); 
			 return false;
		 }
			return flag;
	}
/**
 *  * This method checks the parameters we have received are not empty
 * if they are poses flag= false;
 * @param sub
 */
	public void check_input(String sub)
	{
		
		if(sub.equals(""))
		{
			set_msg("\nmising subject name ");
			flag=false;
		}

		
	}




	



	


}
